﻿using SuporeSliplampApp.Models;
using SuporeSliplampApp.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SuporeSliplampApp.Views
{
    /// <summary>
    /// AdminView.xaml 的交互逻辑
    /// </summary>
    public partial class AdminView : Window
    {

        public static event EventHandler<bool> adminDelegate;

        private bool _isAdmin;
        public AdminView()
        {
            InitializeComponent();
            if (Common.isAdminMode)
            {
                StopBtn.Visibility = Visibility.Visible;
            }
            else
            {
                StopBtn.Visibility = Visibility.Collapsed;
            }

        }

        private void CancelBtn_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void SaveBtn_Click(Object sender, RoutedEventArgs e)
        {
            try
            {
                if (AdminPasswordBox.Password == "Supore")
                {
                    Common.isAdminMode = true;
                    _isAdmin = true;
                    adminDelegate?.Invoke(this, _isAdmin);
                }
                else
                {
                    MessageBox.Show("密码错误");
                }
            }
            catch { }

            finally
            {
                this.Close();
            }



        }

        private void StopBtn_Click(Object sender, RoutedEventArgs e)
        {
            try
            {
                Common.isAdminMode = false;
                _isAdmin = false;
                adminDelegate?.Invoke(this, _isAdmin);
            }
            catch { }
            finally
            {
                this.Close();
            }
        }


    }
}
